package uk.co.q3c.deplan.client.ui.view;

import java.util.TreeMap;

import uk.co.q3c.deplan.client.ui.component.CaptionGroup;
import uk.co.q3c.deplan.client.ui.component.HorizontalFlowPanel;

import com.google.gwt.user.client.ui.Widget;

public abstract class Q3ViewBasePanel extends Q3ViewBase {
	protected final String topBand = "topBand";

	protected final TreeMap<String, HorizontalFlowPanel> bands;
	private final TreeMap<String, CaptionGroup> groups;

	/**
	 * 
	 */
	public Q3ViewBasePanel() {
		super();
		bands = new TreeMap<String, HorizontalFlowPanel>();
		groups = new TreeMap<String, CaptionGroup>();
	}

	protected void layout() {
		basePanel.add(addBand(topBand));
	}

	protected HorizontalFlowPanel addBand(String bandName) {
		HorizontalFlowPanel hfp = new HorizontalFlowPanel();
		bands.put(bandName, hfp);
		basePanel.add(hfp);
		return hfp;
	}

	protected CaptionGroup addGroup(String groupName) {
		CaptionGroup cg = new CaptionGroup();
		groups.put(groupName, cg);
		return cg;
	}

	protected CaptionGroup addGroup(String groupName, String bandName) {
		CaptionGroup cg = addGroup(groupName);
		HorizontalFlowPanel band = bands.get(bandName);
		band.add(cg);
		return cg;
	}

	/**
	 * Creates a {@link CaptionGroup} with the given name and assigns it to the
	 * band specified by <code>bandName</code>
	 * 
	 * @param groupName
	 * @param bandName
	 */
	protected void assignGroupToband(String groupName, String bandName) {
		CaptionGroup cg = groups.get(groupName);
		HorizontalFlowPanel band = bands.get(bandName);
		band.add(cg);
	}

	protected void assignWidgetToGroup(Widget widget, String groupName) {
		CaptionGroup cg = groups.get(groupName);
		cg.add(widget);
	}

	protected void assignWidgetToBand(Widget widget, String bandName) {
		HorizontalFlowPanel hfp = bands.get(bandName);
		hfp.add(widget);
	}

}
